package com.zut.edu;

import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.qmuiteam.qmui.util.QMUIDisplayHelper;
import com.qmuiteam.qmui.util.QMUIStatusBarHelper;
import com.qmuiteam.qmui.widget.QMUIRadiusImageView;
import com.qmuiteam.qmui.widget.QMUITopBar;
import com.qmuiteam.qmui.widget.QMUITopBarLayout;
import com.qmuiteam.qmui.widget.grouplist.QMUICommonListItemView;
import com.qmuiteam.qmui.widget.grouplist.QMUIGroupListView;
import com.zut.edu.utils.CameraUtils;
import com.zut.edu.utils.StringUtils;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MineActivity extends AppCompatActivity {
    @BindView(R.id.mine_userhead)
    QMUIRadiusImageView mineuserhead;
    @BindView(R.id.mine_groupListView)
    QMUIGroupListView minegroupListView;
    @BindView(R.id.mine_topbar)
    QMUITopBarLayout minetopbar;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mine);
        ButterKnife.bind(this);
        QMUIStatusBarHelper.translucent(this);
        initGroupListView();
        initTopBar();
    }
    private void initTopBar(){
        minetopbar.setTitle("我的资料");
        minetopbar.setBackgroundAlpha(0);
        minetopbar.setBottomDividerAlpha(0);
        minetopbar.addLeftBackImageButton().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
    }
    private QMUICommonListItemView initItem(int id,String key,String value){
        QMUICommonListItemView item = minegroupListView.createItemView(
                ContextCompat.getDrawable(this, id),
                key,
                value,
                QMUICommonListItemView.HORIZONTAL,
                QMUICommonListItemView.ACCESSORY_TYPE_NONE);
        return item;
    }

    private void initGroupListView(){
        CameraUtils.initRadiusImageView(mineuserhead,R.mipmap.user_head);
        StringUtils.photoURL(MineActivity.this,StringUtils.getLocalitem(this,"user","userPhoto"),mineuserhead);
        mineuserhead.setBorderWidth(5);
        QMUICommonListItemView item1 = initItem(R.drawable.plugin_mine_user_id,"UID", StringUtils.getLocalitem(this,"user","userId"));
        QMUICommonListItemView item2 = initItem(R.drawable.plugin_left_menu_mine,"姓名",StringUtils.getLocalitem(this,"user","userName"));
        QMUICommonListItemView item3 = initItem(R.drawable.plugin_mine_account,"账号",StringUtils.getLocalitem(this,"user","userAccount"));
        QMUICommonListItemView item4 = initItem(R.drawable.plugin_mine_identity,"身份",StringUtils.statusJudge("userIdentity",StringUtils.getLocalitem(this,"user","userIdentity")));
        QMUICommonListItemView item5 = initItem(R.drawable.plugin_mine_status,"状态","正常");
        int size = QMUIDisplayHelper.dp2px(this, 20);
        QMUIGroupListView.newSection(this)
                .setLeftIconSize(size, ViewGroup.LayoutParams.WRAP_CONTENT)
                .addItemView(item1,null)
                .addItemView(item2,null)
                .addItemView(item3,null)
                .addItemView(item4,null)
                .addItemView(item5,null)
                .setMiddleSeparatorInset(QMUIDisplayHelper.dp2px(this, 20), 0)
                .addTo(minegroupListView);



        QMUICommonListItemView item6 = initItem(R.drawable.plugin_mine_user_id,"CID", StringUtils.getLocalitem(this,"company","companyId"));
        QMUICommonListItemView item7 = initItem(R.drawable.plugin_mine_company,"公司名称",StringUtils.getLocalitem(this,"company","companyName"));
        QMUICommonListItemView item8 = initItem(R.drawable.plugin_mine_location,"公司地点",StringUtils.getLocalitem(this,"company","companyLocation"));
        QMUIGroupListView.newSection(this)
                .setLeftIconSize(size, ViewGroup.LayoutParams.WRAP_CONTENT)
                .addItemView(item6,null)
                .addItemView(item7,null)
                .addItemView(item8,null)
                .setMiddleSeparatorInset(QMUIDisplayHelper.dp2px(this, 20), 0)
                .addTo(minegroupListView);
    }
}
